<template>
	<view class=" ">
		<view class="padding ">
			<view class="rowsc" style="margin-top: 100rpx;">
				<image src="/static/logo.png" mode="aspectFill" style="height: 150rpx;width: 150rpx;" class="radius"></image>
			</view>

			<view class="  padding  align-center " style="margin-top: 50rpx;">
				<view style="width: 100rpx;">用户名</view>
				<input type="number" maxlength="11" placeholder="请输入手机号码" class=" border  radius" v-model="phone" 
				style="padding: 30rpx; width: 80%;" />
			</view>
			<view class="  padding   align-center  margin-top-sm">
				<view style="width: 100rpx;">密码</view>
				<input type="password" placeholder="请输入登录密码" class="border" v-model="password" style="padding: 30rpx;width: 80%;" />
			</view>
			<view class="rowsc">
				<view style=" margin-top: 10rpx;width: 100%;background-color: #0054A7;color: white;" class="padding-sm radius  text-center text-xl " @click="submitMen">
					登录
				</view>
			</view>
			<view class=" text-sm text-gray justify-end margin-top-sm">
				<!-- <view @click="wangjimima">重置密码</view> -->
				<view @click="register">去注册</view>
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp().globalData
	import {
		login
	} from '../../common/path.js'
	export default {
		data() {
			return {
				phone: '',
				password: '',
			}
		},
		methods: {
			wangjimima(){
				uni.navigateTo({
					url:'password'
				})
			},
			login() {
				let data = {
					tel: this.phone,
					password: this.password
				}
				this.$axios.axios('POST', login, data)
					.then(res => {
						console.log('登录=============>', res.data);
						if (res.status == 1) {
							uni.showToast({
								title:'登录成功'
							})
							app.userInfo = res.data
							uni.setStorageSync('userInfo', res.data)
							setTimeout(r=>{
								uni.reLaunch({
									url:'../home/home/home'
								})
							},1000)
						} else {
							this.$tools.showToast(res.msg)
						}
					})
					.catch(err => {
						this.$tools.showToast('数据请求失败')
						console.log(err);
					})
			},
			submitMen() {
				if (this.phone == '' || this.phone.length != 11) {
					this.$tools.showToast("手机号错误")
				} else if (this.password == "") {
					this.$tools.showToast("密码错误")
				} else {
					this.login()
				}
			},
			register() {
				uni.navigateTo({
					url: 'register'
				})

			}
		}
	}
</script>

<style>
	page {
		background-color: #FFFFFF;
	}

	.solid-bottom-white {
		border-bottom: 1rpx solid #FFFFFF;
		order: 0.6;
	}
</style>
